﻿<%@ Page Title="查找/添加好友" Language="C#" MasterPageFile="~/member/mMenber.master" AutoEventWireup="true" CodeBehind="searchFriends.aspx.cs" Inherits="map.member.searchFriends" %>


<%@ Register Assembly="RuleCode.Common" Namespace="RuleCode.Controls" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head2" runat="server">
          <link href="../outstyle.css" rel="stylesheet" type="text/css" />
      <link href="../Stylesheet1.css" rel="stylesheet" type="text/css" />
      <script src="../js/dropdowncontent.js" type="text/javascript"></script>
      <style type ="text/css"> 
        .input-button,.input-submit{background-color:#005eac;border-color:#b8d4e8 #124680 #124680 #b8d4e8;border-style:solid;border-width:1px;color:#fff;cursor:pointer;font-size:12px;padding:2px 15px;text-align:center}
        .searchBoxDiv
        {
             padding-left:30px;
             font-size:large;
             margin-top:20px;
             margin-bottom:20px;
        }
        .totalContentDiv
        {
            width:1000px;
        }
        .searchResultDiv
        {
            border:solid 1px lightBlue;
        }
        .searchResultFilterDiv
        {
            border-bottom:solid 1px lightBlue;
            height:20px;
            margin-top:10px;
            padding-right:10px;
            text-align:right ;
            padding-bottom:10px;
        }
         .DataListDiv
        {
            background-color:#F0F5F8;
            border:solid 1px lightGray;
        }
        .DataListTable
        {
            margin:4px 0px 4px 0px;
            border:solid 1px lightGray;
            width:100%;
            background-color:White ;
        }
        .DataListTable li
        {
            list-style-type:none;
        }
      </style>
      
    <link href="../css/popup.css" rel="stylesheet" type="text/css" />
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">
     
<asp:UpdatePanel ID="MainUpdatePanel"  runat="server">
     <ContentTemplate>
     <div class ="totalContentDiv">
        <div class ="searchBoxDiv">
            <input type ="text" id="searchKeysInputText" style =" width:200px;" runat="server" value ="可输入姓名 学校 单位"  onblur ="if(this.value=='') this.value='可输入姓名 学校 单位';"  onfocus ="if(this.value=='可输入姓名 学校 单位')this.value='';"/>
            <input id="normalSearchButton" type ="button" class="input-button" value="搜索" onserverclick ="SearchButton_Click" runat="server"/>
            <a href ="advanceSearch.aspx" style="  padding-top:2px;;color:#3300CC">高级搜索</a>
        </div>
        <div class="searchResultDiv">
            <div class ="searchResultFilterDiv">
                 <span style =" font-weight:bold;">筛选：</span>
                <asp:DropDownList ID="SexDropDownList" AutoPostBack="true" Width="80px" runat="server" 
                     onselectedindexchanged="SexDropDownList_SelectedIndexChanged">
                    <asp:ListItem Value ="All" Selected="true" Text ="选择性别"></asp:ListItem>
                    <asp:ListItem Value ="男" Text ="男"></asp:ListItem>
                    <asp:ListItem Value ="女" Text ="女"></asp:ListItem>
                </asp:DropDownList>
                <asp:DropDownList ID="StateDropDownList" AutoPostBack="true" Width="80px" runat="server" 
                     onselectedindexchanged="StateDropDownList_SelectedIndexChanged">
                </asp:DropDownList>
                <asp:DropDownList ID="CityDropDownList" AutoPostBack="true" Width="80px" runat="server" 
                     onselectedindexchanged="CityDropDownList_SelectedIndexChanged">
                </asp:DropDownList>
                <input  type ="text" id="CollageTextInput"  onserverchange ="CollageTextInput_TextChanged" style =" margin:0px 0px 0px 0px; width:120px;" value="请输入大学" runat="server" onblur ="if(this.value=='')this.value='请输入大学';" onfocus ="if(this.value=='请输入大学')this.value='';"/>
            </div>
            <div class ="DataListDiv">
                <div style =" margin:5px 5px 5px 5px;">
                     <asp:DataList ID="MainDataList" Width="100%" runat="server">
                        <ItemTemplate>
                            <table class ="DataListTable">
                                 <tr>
                                    <td style =" width:70px">
                                        <a href ="#">
                                            <img alt ="" style =" width:60px; height :50px; border:none"  src ='<%#(Eval("cbimgpath").ToString()=="")?"../img/userdefaultimg.gif":Eval("cbimgpath") %>'/>
                                        </a>
                                    </td>
                                    <td style =" text-align:left ">
                                        <%# GetUlHtml (Eval("cbname").ToString(),Eval("ColleageName").ToString(),Eval("JuniorSchoolName").ToString(),Eval("SeniorSchoolName").ToString(),Eval("LastEmployeeName").ToString() )%>
                                    </td>
                                    <td style =" width:20%; text-align :left ;">
                                         <ul>
                                            <li>
                                                <a href ="#" onclick="showaddNewFriends(this);">加为好友</a>
                                                <input  value='<%#(Eval("cbimgpath").ToString()=="")?"../img/userdefaultimg.gif":Eval("cbimgpath") %>' type ="hidden" />
                                                <input value='<%#Eval("cbuserid").ToString() %>' type ="hidden"/>
                                                <input value='<%#Eval("cbname").ToString() %>' type ="hidden"/>
                                            </li>
                                         </ul>
                                    </td>
                                 </tr>
                            </table>
                        </ItemTemplate>
                     </asp:DataList>
                     <div id="NoFriendsDataDiv" style =" width:100%; background-color:#FCFBCC;   margin-top:2px; margin-bottom:2px; display:none;" runat="server">
                        <span style="color:red;font-size:small;">对不起，没有找到符合您要求的朋友！</span>
                     </div>
                     <div style =" background-color:lightGray ;">
                     <cc1:WebPager ID="MainWebPager"  PageSize ="10" OnPageIndexChanged ="MainWebPager_PageIndexChanged"
                        ControlToPaginate ="MainDataList" PagerStyle="NumericPages" runat="server" />
                     </div>
                        
                </div>
            </div>
        </div>
     </div>
     
     
       <%--添加好友--%>
        <div class="sample_popup" id="popup" style=" position:absolute ; height:200px; width :400px; z-index :2;  display :none; ">
            <div class="menu_form_header" id="popup_drag">
                <table>
                    <tr>
                        <td>
                            添加好友：
                        </td>
                        <td>
                            <img alt="" class="menu_form_exit" onclick="document.getElementById('popup_exit').click()" src="../img/closes.png" />
                        </td>
                    </tr>
                </table>
            </div>
            <div class="menu_form_body">    
                <div style =" width :100%;">
                    <table width="100%">
                        <tr>
                            <td style =" width:200px;">
                                <table width="200px">
                                    <tr>
                                        <td colspan="2">
                                            您将添加 <a id="NewFriendIdAnchor" style=" text-decoration:underline" href ="#"></a>为好友
                                            <input type ="hidden"  value="" id="NewFriendIdHiddenInput" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td  >
                                            <span style =" text-align :left ">选择分组：</span>
                                        </td>
                                        <td>
                                            <select id="NewFriendGroupSelect">
                                                <option value ="" selected ="true">请选择分组</option>
                                            </select>
                                        </td>
                                    </tr>                        
                                    <tr>
                                        <td >
                                            <span style =" text-align :left ">备注(可选)：</span>
                                        </td>
                                        <td style =" text-align:left">
                                            <input id="FriendNickText" type="text" style="width: 100px" />
                                        </td>
                                    </tr>
                                </table>                                         
                            </td>
                            <td style =" width:100px; text-align:center;">
                                <img  style =" padding-top:10px; width:80px; height :80px;" id="NewFriendImg"/>
                            </td>
                        </tr>
                    </table>                             
                </div>
                <div style="text-align: center;  width: 100%">
                    <input id="AddButton" type="button" value="增加" onclick=" if( addFriend()==true) document.getElementById('popup_exit').click();" />
                    <input id="popup_exit" type="button" value="取消"  />
                </div>
                <%-- <input id="GroupIdHidden" type="hidden"  />--%>
            </div>
        </div>
        
        <div id="maskDiv" style =" position :absolute ;top:0px; left :0px;   visibility :hidden ; background-color :#666;  z-index :1;"></div>
    
  </ContentTemplate>
</asp:UpdatePanel>   
    <script src="../js/PopupDiv.js" type="text/javascript"></script>
     <script type ="text/javascript">
         var searchKeysInputText = document.getElementById("ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder3_" + "searchKeysInputText");
         searchKeysInputText.onkeydown = function(o) {
             o = o || window.event;
             if (o.keyCode == "13") {
                 document.getElementById("ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder3_" + "normalSearchButton").click();
             }
         }
         
         function searchKeysButtonClick() {
             var searchKeys = document.getElementById("searchKeysInputText").value;
             if (searchKeys == "可输入姓名 学校 单位") {
                 searchKeys = "%";
             }
             window.location.href = "searchFriends.aspx?type=0&searchkeys=" + encodeURI(searchKeys);
         }

         //添加好友
         function showaddNewFriends(thisObj) {
             var thisObjHiddenInputs = thisObj.parentNode.getElementsByTagName("input");
             var friendImgPath = thisObjHiddenInputs[0].value;
             var friendsId = thisObjHiddenInputs[1].value;
             var friendsName = thisObjHiddenInputs[2].value;
             var currentUserId = AjaxFunction.GetCurrentUserId().value;
             if (currentUserId != null && currentUserId != "") {
                 var mtop = parseInt(250) + "px";
                 var mleft = parseInt( 350) + "px";
                 initAddFriendDiv(friendsId, friendsName, friendImgPath, currentUserId);
                 popup_show('popup', 'popup_drag', 'popup_exit', mtop, mleft, true, 'maskDiv', 50);
             }
             else {
                 clearAddFriendDiv();
                 alert("对不起，您还未登录，请先登录！");
                 window.location.href = "../member/login.aspx";
             }
         }
         function clearAddFriendDiv() {
             document.getElementById("NewFriendImg").src = "";
             document.getElementById("NewFriendIdAnchor").innerHTML = "";
             document.getElementById("NewFriendIdHiddenInput").value = "";
             document.getElementById("FriendNickText").value = "";
             var friendGroupSelect = document.getElementById("NewFriendGroupSelect");
             friendGroupSelect.innerHTML = "";
             var newOptionEle = document.createElement("option");
             newOptionEle.innerHTML = "请选择分组";
             newOptionEle.value = "";
             newOptionEle.selected = "true";
             friendGroupSelect.appendChild(newOptionEle);
         }
         function initAddFriendDiv(friendsId, friendsName, friendImgPath, currentUserid) {
             document.getElementById("NewFriendImg").src = friendImgPath;
             document.getElementById("NewFriendIdAnchor").innerHTML = friendsName;
             document.getElementById("NewFriendIdHiddenInput").value = friendsId;
             document.getElementById("FriendNickText").value = friendsName;
             var friendGroupSelect = document.getElementById("NewFriendGroupSelect");
             friendGroupSelect.innerHTML = "";
             var newOptionEle = document.createElement("option");
             var allGroupResult = AjaxFunction.GetCurrentGroupList();
             if (allGroupResult.value != null && allGroupResult.value != "") {
                 var allGroupList = eval(allGroupResult.value);
                 for (var i = 0; i < allGroupList.length; i++) {
                     newOptionEle = document.createElement("option");
                     if (i == 0)
                         newOptionEle.selected = "true";
                     newOptionEle.value = allGroupList[i].id;
                     newOptionEle.innerHTML = allGroupList[i].name;
                     friendGroupSelect.appendChild(newOptionEle);
                 }
             }
         }
         function addFriend() {
             var friendsName = document.getElementById("NewFriendIdAnchor").innerHTML;
             var friendsId = document.getElementById("NewFriendIdHiddenInput").value;
             var friendsNick = document.getElementById("FriendNickText").value;
             if (friendsNick.replace(/\s/g, "") == "") {
                 alert("对不起，好友昵称不能为空！");
                 return false;
             }
             var friendGroupSelect = document.getElementById("NewFriendGroupSelect");
             var friendsGroupId = friendGroupSelect[friendGroupSelect.selectedIndex].value;
             var result = AjaxFunction.AddNewFriend(friendsGroupId, friendsId, friendsNick);
             if (result.value != null && result.value == "") {
                 document.getElementById("ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder3_normalSearchButton").click();
                 alert("添加成功");
                 return true;
             }
             else {
                 if (result.value == null)
                     alert("添加失败");
                 else
                     alert(result.value);
                 return false;
             }
         }
     </script>
</asp:Content>
